#ifndef MAGLEVVEHICLE_H
#define MAGLEVVEHICLE_H

#include <QGraphicsPixmapItem>
#include <QPropertyAnimation>
#include <QColor>
#include <QPixmap>
#include <QtMath>
#include <QCursor>

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

class TrackSegment;

class MaglevVehicle : public QGraphicsPixmapItem
{
public:
    MaglevVehicle(QGraphicsItem* parent = nullptr);
    
    void setColor(const QColor& color);
    QColor color() const { return m_color; }
    
    void setSize(const QSizeF& size);
    QSizeF size() const { return m_size; }
    
    void setSpeed(double speed);
    double speed() const { return m_speed; }
    
    void setCurrentSegment(TrackSegment* segment);
    TrackSegment* currentSegment() const { return m_currentSegment; }
    
    void setPositionOnSegment(double distance);
    double positionOnSegment() const { return m_positionOnSegment; }
    
    void startAnimation();
    void pauseAnimation();
    void stopAnimation();
    
    void updatePosition();
    
    bool isDragging() const { return m_isDragging; }
    void setDragging(bool dragging) { m_isDragging = dragging; }
    
protected:
    void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
    void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
    void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override;
    
private:
    QColor m_color;
    QSizeF m_size;
    double m_speed;
    
    TrackSegment* m_currentSegment;
    double m_positionOnSegment;
    
    QPropertyAnimation* m_animation;
    bool m_isDragging;
    
    void createPixmap();
};

#endif // MAGLEVVEHICLE_H
